# 写入 test.txt 文件
with open('test.txt', 'w') as file:
    file.write('Hello, this is the first line.\n')
    file.write('And this is the second line.\n')
    file.write('Finally, this is the third line.\n')

# 读取 test.txt 并创建 newtest.txt
with open('test.txt', 'r') as input_file:
    # 读取所有行
    lines = input_file.readlines()

with open('newtest.txt', 'w') as output_file:
    for idx, line in enumerate(lines):
        # 删除末端的换行符然后添加行号和行长度
        new_line = f"{idx + 1}: {line.strip()}\n" # 这里去掉 strip() 也可以，取决于长度计算时是否包括换行符等
        new_line_length = len(new_line) - 1 # 减去一个为了不计算末尾的新行
        new_line = f"{new_line.strip()}{new_line_length}\n"
        output_file.write(new_line)

print("File 'newtest.txt' has been created with modified content.")